package com.airlenet.dubbo.demo.service;

import com.airlenet.dubbo.demo.api.HelloApi;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.rpc.RpcContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.management.ManagementFactory;

@DubboService
public class HelloApiImpl implements HelloApi {
    private static final Logger logger = LoggerFactory.getLogger(HelloApi.class);

    @Override
    public String sayHello(String hi) {

        logger.info("from {}:{} say:{}", RpcContext.getContext().getRemoteHost(), RpcContext.getContext().getRemotePort(), hi);
        return ManagementFactory.getRuntimeMXBean().getName() + " :" + RpcContext.getContext().getLocalHost() + ":" + RpcContext.getContext().getLocalPort() + "I'm Provider ";
    }

    @Override
    public HelloResponse sayObject(HelloRequest req) {
        logger.info("from {}:{} say:{}", RpcContext.getContext().getRemoteHost(), RpcContext.getContext().getRemotePort(), req);
        return new HelloResponse(true, req.getUuid(), req.getMessage());
    }
}
